layui.define([ 'form', 'laydate', 'table','userApi' ], function(exports) {
	var form = layui.form;
	var laydate = layui.laydate;
	var table = layui.table;
	var userApi=layui.userApi;
	var userTable = null;
	
	var view ={
		
		init:function(){
			this.initTable();
			this.initSearchForm();
			this.initToolBar();
			window.dataReload = function(){
				Lib.doSearchForm($("#searchForm"),userTable)
			}
		},

		initTable:function(){
			userTable = table.render({
				elem : '#userTable',
				height : Lib.getTableHeight(),
				method : 'post',
				url : Common.ctxPath + '/cms/employeeManager/examineList.json' //数据接口
				,page : Lib.tablePage //开启分页
				,limit : 10,
				cols : [ [ //表头
				{
					type : 'checkbox',
					fixed:'left',
				}, {
					field : 'code',
					title : '登录账号',
                        align: 'center',
                        width:"200"
				}, {
					field : 'name',
					title : '用户姓名',
                        align: 'center',
                        width:"200"
				}, {
					field : 'stateText',
					title : '状态',
                        align: 'center',
                        width:"90"
				}/*, {

                        field : 'roleName',
                        title : '用户类型',
                        align: 'center',
                        width:"90"
                    }*/
				] ]

			});
		},
		
		initSearchForm:function(){
			Lib.initSearchForm( $("#searchForm"),userTable,form);
		},
		initToolBar:function(){
			toolbar = {
					add : function() { //获取选中数据
						var url = "/cms/employeeManager/examineAdd.do";
						Common.openDlg(url,"企业开户>新增");
					},
					edit : function() { //获取选中数目
						var data = Common.getOneFromTable(table,"userTable");
						if(data==null){
							return ;
						}
						var url = "/cms/employeeManager/examineEdit.do?id="+data.id;
						Common.openDlg(url,"企业开户>编辑");
						
					},
                    del : function() {
                        layui.use(['del'], function(){
                            var delView = layui.del
                            delView.ExamineDel();
                        });
                    },
                    disable : function() {
                        var data = Common.getMoreDataFromTable(table,"userTable");
                        if(data==null){
                            return ;
                        }
                        Common.openConfirm("确认要禁用这些用户?",function(){
                            var ids =Common.concatBatchId(data);
                            Common.post("/cms/employeeManager/examineDisable.json", {
                                "ids" : ids
                            }, function() {
                                Common.info("禁用成功");
                                dataReload();
                            })
                        })
                    },
                    enable : function() {
                        var data = Common.getMoreDataFromTable(table,"userTable");
                        if(data==null){
                            return ;
                        }
                        Common.openConfirm("确认要启用这些用户?",function(){
                            var ids =Common.concatBatchId(data);
                            Common.post("/cms/employeeManager/examineEnable.json", {
                                "ids" : ids
                            }, function() {
                                Common.info("启用成功");
                                dataReload();
                            })
                        })
                    },
					changePassword:function(){
						var data = Common.getOneFromTable(table,"userTable");
						if(data==null){
							return ;
						}
						var url = "/cms/employeeManager/examineChangePassword.do?id="+data.id;
						Common.openDlg(url,"重置密码");
					},
                checkPassword:function () {
                    var data = Common.getOneFromTable(table,"userTable");
                    if(data==null){
                        return ;
                    }
                    Common.openDlg("/jsPrint.html?id="+data.id,"密码函");
                }
				};
			$('.ext-toolbar').on('click', function() {
				var type = $(this).data('type');
				toolbar[type] ? toolbar[type].call(this) : '';
			});
		}
	}

	 exports('examineIndex',view);
	
});